<script lang="ts" setup>
    import {reactive,ref,onMounted,watch,defineEmits}  from 'vue'
    import { ElMessageBox,TabsPaneContext,ComponentSize, FormInstance, FormRules } from 'element-plus'
    import {useRouter,useRoute} from 'vue-router'
    let router=useRouter();
    let route=useRoute();
    let breadList=ref([]);
    let props = defineProps(['change'])
    const emit=defineEmits(['update:change']);
    let dropdown17 = ref()//消息通知
    let isblock=ref(false);
     //修改密码的弹框
     let dialogVisible = ref(false)
     let dialogVisible1 = ref(false)
    //  let dialogTableVisible1 = ref(false)

    
      //消息
      const activeName = ref('1')

      const handleClick = (tab: TabsPaneContext, event: Event) => {
        console.log(tab, event)
      }








    //打开修改密码弹窗
    let openpass=()=>{
        dialogVisible.value=true;
        ruleForm = reactive<RuleForm>({
            password:'',
            newpass:'',
            repass:''
        })
    }

    // 打开头像弹框
    let changeimg=()=>{
        dialogVisible1.value=true;
    }

    //修改密码弹框中的form表单
interface RuleForm {
    password:String,
    newpass:String,
    repass:String
}

const formSize = ref<ComponentSize>('default')
const ruleFormRef = ref<FormInstance>()
let ruleForm = reactive<RuleForm>({
    password:'',
    newpass:'',
    repass:''
})


const rules = reactive<FormRules<RuleForm>>({
    password: [
    { required: true, message: '请输入旧密码', trigger: 'blur' },
    { min: 6, max: 10, message: '必须输入6-10位数', trigger: 'blur' },
  ],
  newpass: [
    { required: true, message: '请输入新密码', trigger: 'blur' },
    { min: 6, max: 10, message: '必须输入6-10位数', trigger: 'blur' },
  ],
  repass: [
    { required: true, message: '请再次输入新密码', trigger: 'blur' },
    { min: 6, max: 10, message: '必须输入6-10位数', trigger: 'blur' },
  ]

})
//确定修改
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
      dialogVisible.value = false
    } else {
      console.log('error submit!', fields)
    }
  })
}
// 取消
let noform=()=>{
    dialogVisible.value = false
}

  //退出登录
  let dellogin=()=>{
    localStorage.removeItem('token');
    router.push('/Login')
  }


  //消息管理
  let showBall=()=>{
    isblock.value=!isblock.value;
  }






   
    //点击缩放
    let some=()=>{
        emit('update:change',!props.change)
    }
    //面包屑
    let getMatched=()=>{
        console.log(route.matched)
        breadList.value=route.matched.filter(item=>item.meta && item.meta.title)
        console.log(breadList.value)
    }
    watch(()=>route.path,(newValue,oldValue)=>{
        console.log(route.matched)
        breadList.value=route.matched.filter(item=>item.meta && item.meta.title)
    })
    onMounted(()=>{
        getMatched()
    })
</script>

<template>
    <div class="left">
        <el-icon @click="some"><Fold /></el-icon>
        <el-breadcrumb separator="/">
            <template v-for="(item,index) in breadList">
                <el-breadcrumb-item 
                v-if="item.name"
                :key="index"
                :to="item.path"
                >
                    {{item.meta.title}}
                </el-breadcrumb-item>
            </template>
        </el-breadcrumb>
    </div>
    <div class="right">
        <el-icon @click="showBall"><Bell/></el-icon>
        <!-- 消息通知 -->
        <el-card shadow="always" class="messgaeBox" v-show="isblock">
          <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
            <el-tab-pane label="未读1条" name="1" style="display:flex;flex-direction:column;justify-content:center;align-items:center;">
              <el-card style="width:98%;min-height:50px;margin-bottom:10px;">
                <div class="top">
                  <p>
                    <el-tag>{{'通知'}}</el-tag>
                    <div>{{'111111111'}}</div>
                  </p>
                  <el-icon size="20"><Close /></el-icon>
                </div>
                <div class="center">
                  <el-tooltip content="标记为已读">
                    <el-icon size="20"><DocumentChecked /></el-icon>
                  </el-tooltip>
                  
                  <p>发送人:{{'管理员'}}</p>
                </div>
                <div class="bottom">
                  <p>{{'2024-05-13 09:12:43'}}</p>
                </div>
              </el-card>
              
            </el-tab-pane>
            <el-tab-pane label="已读一条" name="2">
              <el-card style="width:98%;min-height:50px;margin-bottom:10px;">
                <div class="tops">
                  <p>
                    <el-tag>{{'通知'}}</el-tag>
                    <div>{{'111111111'}}</div>
                  </p>
                  <el-icon size="20"><Close /></el-icon>
                </div>
                <div class="centers">
                  <p>发送人:{{'管理员'}}</p>
                </div>
                <div class="bottoms">
                  <p>{{'2024-05-13 09:12:43'}}</p>
                </div>
              </el-card>
            </el-tab-pane>
          </el-tabs>
        </el-card>
        <el-dropdown trigger="click">
        <div class="rightall">
            <div class="adminImg el-dropdown-link"></div>
            <p class="el-dropdown-link">管理员</p>
        </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item>首页</el-dropdown-item>
        <el-dropdown-item>项目地址</el-dropdown-item>
        <el-dropdown-item @click="openpass">修改密码</el-dropdown-item>
        <el-dropdown-item @click="changeimg">更新头像</el-dropdown-item>
        <el-dropdown-item @click="dellogin">登出</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
    </div>
        <!-- 修改密码的弹框 -->
        <el-dialog
    v-model="dialogVisible"
    title="修改密码"
    width="500"
  >
  <el-form
    ref="ruleFormRef"
    style="max-width: 600px"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
    class="demo-ruleForm"
    :size="formSize"
    status-icon
  >
    <el-form-item label="旧密码" prop="password">
      <el-input v-model="ruleForm.password"/>
    </el-form-item>
    <el-form-item label="新密码" prop="newpass">
      <el-input v-model="ruleForm.newpass"/>
    </el-form-item>
    <el-form-item label="重复密码" prop="repass">
      <el-input v-model="ruleForm.repass"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        确定修改
      </el-button>
      <el-button @click="noform()">取消</el-button>
    </el-form-item>
  </el-form>
        </el-dialog>
        <!-- 更新头像弹框 -->
        <el-dialog
        v-model="dialogVisible1"
        title="更新头像"
        width="600"
  >
   1111
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible1 = false">确认并上传</el-button>
        <el-button type="primary" @click="dialogVisible1 = false">
          取消
        </el-button>
      </div>
    </template>
  </el-dialog>

  
</template>

<style lang="less" scoped>
   .left{
    min-width:100px;
    height:60px;
    display: flex;
    justify-content:space-evenly;
    align-items: center;
   }
   .right{
      position:relative;
      width:150px;
      height:60px;
      display: flex;
      justify-content:space-evenly;
      align-items: center;
      margin-right:50px;
      .messgaeBox{
        position:absolute;
        top:60px;
        right:-46px;
        width:400px;
        height:300px;
        z-index:999;
        overflow:auto;
        background-color:#fefefe;
        .top{
          width:100%;
          min-height:50px;
          display:flex;
          justify-content:space-between;
          p{
            width:80%;
            min-height:50px;
            display:flex;
            justify-content:space-between;
            div{
              width:80%;
              min-height:50px;
            }
          }
          .el-icon{
            width:20%;
            height:100%;
            display:flex;
            flex-direction:column;
            padding-top:16px;
            padding-left:50%;
          }
        }
        .center{
          width:100%;
          height:30px;
          display:flex;
          justify-content:space-between;
          align-items:center;

        }
        .bottom{
          width:100%;
          height:30px;
          display:flex;
          justify-content:end;
          align-items:center;
        }
        .tops{
          width:100%;
          min-height:50px;
          display:flex;
          justify-content:space-between;
          p{
            width:80%;
            min-height:50px;
            display:flex;
            justify-content:space-between;
            div{
              width:80%;
              min-height:50px;
            }
          }
          .el-icon{
            width:20%;
            height:100%;
            display:flex;
            flex-direction:column;
            padding-top:16px;
            padding-left:50%;
          }
        }
        .centers{
          width:100%;
          height:30px;
          display:flex;
          justify-content:end;
          align-items:center;
        }
        .bottoms{
          width:100%;
          height:30px;
          display:flex;
          justify-content:end;
          align-items:center;
        }
      }
      .demo-tabs > .el-tabs__content {
        padding: 32px;
        color: #6b778c;
        font-size: 32px;
        font-weight: 600;
      }

   }
   .adminImg{
    width:30px;
    height:30px;
    background-color:white
   }
   .example-showcase .el-dropdown-link{
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
.rightall{
    width:100px;
    height:60px;
    display: flex;
  justify-content: space-evenly;
  align-items: center;
}

</style>
